# coding:utf-8
# 创建和访问字典
empty = {}
# print (empty)
# print (type(empty))

# dict() 函数的参数可以是一个序列（但不能是多个），所以要打包成一个元组序列（列表也可以）
dict1 = dict((('F', 70), ('i', 105), ('s', 115), ('h', 104), ('C', 67)))
# print(dict1)

# 具有映射关系的函数
dict1 = dict(F=70, i=105, s=115, h=104, C=67)
dit1 = 'F=70', 'i=105', 's=115', 'h=104', 'C=67'
# print(dict1)

# 创建同样字典
a = dict(one=1, two=2, three=3)
b = {'one': 1, 'two': 2, 'three': 3}
c = dict(zip(['one', 'two', 'three'], [1, 2, 3]))
d = dict([('two', 2), ('one', 1), ('three', 3)])
e = dict({'three': 3, 'one': 1, 'two': 2})
# print (a==b==c==d==e)

# formkeys()
dict1 = {}
# print (dict1.fromkeys((1,2,3)))

dict2 = {}
# print (dict2.fromkeys(1,2,3),"Number")

dict3 = {}
# print (dict3.fromkeys((1,2,3),("one","two","three")))

# keys() values() items()
dict1 = {}
dict1 = dict1.fromkeys(range(32), "赞")
# print(dict1.keys())
# print(dict1.values())
# print(dict1.items())
# print (dict1)

dict1.clear()
# print (dict1)

a = {1: "one", 2: "two", 3: "three"}
b = a.copy()
# print (id(a))
# print (id(b))
a[1] = 'four'


# print (a)
# print (b)

# 收集参数两种打包形式：一种是以元组的形式打包，一种是以字典的形式打包

# 解包
def test(**params):
    print("有%d个参数" % len(params))
    print("它们分别是：", params)


# test(a=1,b=2,c=3,d=4,e=5)
# 打包
a = {"one": 1, "two": 2, "three": 3}
# test(**a)

# 7.2 集合唯一
num1 = {}
# print (type(num1))

num2 = {1, 2, 3, 4, 5}
# print (type(num2))

num = {1, 2, 3, 4, 5, 4, 3, 2, 1}
# print (num)

list1 = [1, 2, 3, 4, 5, 5, 3, 1, 0]
temp = list1[:]
list1.clear()
for each in temp:
    if each not in list1:
        list1.append(each)
# print(list1)

list1 = [1,2,3,4,5,3,1,0]
list1 = list(set(list1))
# print (list1)

# 访问集合
set1 = {1,2,3,4,5,4,3,2,1,0}
# for each in set1:
#      print (each,end=' ')

# 不可变集合
set1 = frozenset({1,2,3,4,5})
set1.add(6)